//
// Created by francklinson on 2021/12/2 AT 10:01.
// May Saint Diana bless you!
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

class Solution {
public:
    int daysBetweenDates(string date1, string date2) {
        return abs(dateToInt(date1) - dateToInt(date2));
    }

    bool isLeap(int year) {
        return (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
    }

    // 给定的日期距离1971.1.1的天数
    int dateToInt(const string &date) {
        int year, month, day;
        sscanf_s(date.c_str(), "%d-%d-%d", &year, &month, &day);
//        year = stoi(date.substr(0, 4));
//        month = stoi(date.substr(5,2));
//        day = stoi(date.substr(8,2));
        int month_length[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int ans = day - 1;
        // 计算这一天在这一年的第几天
        while (month != 0) {
            --month;
            ans += month_length[month];
            // 闰年
            if (month == 2 && isLeap(year))
                ans += 1;
        }
        // 中间的年数
        ans += 365 * (year - 1971);
        // 今年是不是闰年已经在上面判断过了，所以是year-1
        ans += (year - 1) / 4 - 1974 / 4; // 能被4整除的
        ans -= (year - 1) / 100 - 1974 / 100; // 能被100整除的
        ans += (year - 1) / 400 - 1974 / 400; // 能被400整除的
        return ans;

    }
};

int main() {
    Solution solution;
    cout << solution.daysBetweenDates("2019-06-29", "2019-06-30") << endl;
    return 0;
}

